#pragma once

#include <vector>
#include <string>
#include "IFinsCommand.h"
#include "qSocket.hpp"

using namespace std;

namespace OmronPlc {
	class tcpFinsCommand : public IFinsCommand {
	private:

		fins_frame_t finsCommand;
		fins_frame_t finsResponse;

		int finsResponseLen = 0;
		byte respFinsData[2048];

		qSocketClient* transport;

	public:
		tcpFinsCommand(uint8_t ServiceID = 0x01);
		virtual ~tcpFinsCommand();
		virtual bool Connect();
		virtual bool IsConnectd();
		virtual void Close();
		virtual void SetRemote(cstr_t ipaddr, uint16_t port);
		virtual bool MemoryAreaRead(MemoryArea area, uint16_t address, uint8_t bit_position, uint16_t count);
		virtual bool MemoryAreaWrite(MemoryArea area, uint16_t address, uint8_t bit_position, uint16_t count, uint8_t data[]);

	private:
		bool NodeAddressDataSend();
		bool FrameSend(byte* data = NULL, int wsize = 0);
		int Send(const uint8_t command[], int cmdLen);
		int Receive(uint8_t response[], int respLen);
	};
}
